﻿using MediatR;
using S.EliminationOrDath.API.Application.Command.SheepDeathCommand;
using S.EliminationOrDath.Domain.Models;
using S.EliminationOrDath.Infrastructure.Interface;

namespace S.EliminationOrDath.API.Application.CommandHandlers.SheepDeathCommandHandler
{
    public class SheepDeathCreateCommandHandler : IRequestHandler<SheepDeathCreateCommand, bool>
    {
        private readonly ISheepDeathRepository _sheepDeathRepository;
        public SheepDeathCreateCommandHandler(ISheepDeathRepository sheepDeathRepository)
        {
            _sheepDeathRepository = sheepDeathRepository;
        }
        /// <summary>
        /// 羊只死亡添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(SheepDeathCreateCommand request, CancellationToken cancellationToken)
        {
            return await _sheepDeathRepository.Add(new DeathModel
            {
                DeathDate= request.DeathDate,
                SheepType= request.SheepType,
                DocumentNumber= request.DocumentNumber,
                EarTag= request.EarTag,
                DeathType= request.DeathType,
                VarietyEnum= request.VarietyEnum,
                DeathSex = request.DeathSex,
                BuildingName= request.BuildingName,
                ColumnName= request.ColumnName,
                Remark= request.Remark,
                CreateBy= request.CreateBy,
                CreateDate= request.CreateDate,
                UpdateBy= request.UpdateBy,
                UpdateDate= request.UpdateDate,
            });
        }
    }
}

